Fix garmin serial tracks. A) eliminate empty track at beginning and B)
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Jan 2004 02:22:41 +0000 (02:22 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Jan 2004 02:22:41 +0000 (02:22 +0000)
avoid mem corruption by allocing and freeing the waypoint list consistently.

gpsbabel/garmin.c

index 2e6612a92c474a3768ed3e9a9fabdcdc83f78555..577e538732adc8df9d7951772baca9edbaa726ea 100644 (file)
@@ -109,15 +109,25 @@ track_read(void)
        int32 ntracks;
        GPS_PTrack *array;
        route_head *trk_head = NULL;
-       waypoint *waypts;
        int trk_num = 0;
        char rtedescbuf[100];
        int i;
 
        ntracks = GPS_Command_Get_Track(portname, &array);
-       waypts = xcalloc(sizeof (waypoint), ntracks);
 
        for(i = 0; i < ntracks; i++) {
+               waypoint *wpt;
+
+               /*
+                * This is probably always in slot zero, but the Garmin
+                * serial spec says these can appear anywhere.  Toss them
+                * out so we don't treat it as an extraneous trackpoint.
+                */     
+               if (array[i]->ishdr) {
+                       continue;
+               }
+
+
                if ((trk_head == NULL) || array[i]->tnew) {
                        trk_head = route_head_alloc();
                        trk_head->rte_num = trk_num;
@@ -128,13 +138,15 @@ track_read(void)
                        route_add_head(trk_head);
                }
 
-               waypts[i].longitude = array[i]->lon;
-               waypts[i].latitude = array[i]->lat;
-               waypts[i].altitude = array[i]->alt;
-               waypts[i].shortname = xstrdup(array[i]->trk_ident);
-               waypts[i].creation_time = array[i]->Time;
+               wpt = waypt_new();
+
+               wpt->longitude = array[i]->lon;
+               wpt->latitude = array[i]->lat;
+               wpt->altitude = array[i]->alt;
+               wpt->shortname = xstrdup(array[i]->trk_ident);
+               wpt->creation_time = array[i]->Time;
                
-               route_add_wpt(trk_head, &waypts[i]);
+               route_add_wpt(trk_head, wpt);
        }
 
        while(--ntracks) {